package com.example.teststatisticesinterface.activity;

import com.example.teststatisticesinterface.base.MyApplication;
import com.example.teststatisticesinterface.view.FloatView;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

public class MyFloatViewActivity extends Activity {
	WindowManager wm = null;
	WindowManager.LayoutParams wmParams = null;
	FloatView myFV = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		createView();
		setContentView(myFV);
	}
	private void createView() {
		myFV = new FloatView(getApplicationContext());
		myFV.setText("MyFistFloatView");
		myFV.setTextColor(Color.RED);// 设置字体颜色
		// 获取WindowManager
		wm = (WindowManager) getApplicationContext().getSystemService("window");
		// 设置LayoutParams(全局变量）相关参数
		wmParams = ((MyApplication) getApplication()).getLayoutParams();
		wmParams.type = 2002;
		wmParams.format = 1;
		wmParams.flags |= 8;
		wmParams.gravity = Gravity.LEFT | Gravity.TOP;// 调整悬浮窗口至左上角
		// 以屏幕左上角为原点，设置x、y初始值
		wmParams.x = 0;
		wmParams.y = 0;
		// 设置悬浮窗口长宽数据
		wmParams.width = 120;
		wmParams.height = 40;
		// 显示myFloatView
		wm.addView(myFV, wmParams);
		
	}
}